package com.appcenter.application.mapper;

import com.appcenter.application.input.Role.GetRolesInput;
import com.appcenter.application.model.Roles;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;



@org.apache.ibatis.annotations.Mapper
@Repository
public interface RolesMapper extends Mapper<Roles> {

    //查询同一个APID下RoleCode是否重复
    @Select("select * from roles where AppId=#{AppId} AND RoleCode=#{RoleCode}")
    public List<Roles> getCodeCount(@Param("AppId") String AppId,@Param("RoleCode") String RoleCode);

    //查询同一个APID下RoleCode是否重复
    @Select("select * from roles where AppId=#{AppId} AND RoleCode=#{RoleCode} and Id<> #{Id}")
    public List<Roles> getCodeCountNoId(@Param("AppId") String AppId,@Param("RoleCode") String RoleCode,@Param("Id") String Id);


    //查询同一个APPID下RoleName是否重复
    @Select("select * from roles where AppId=#{AppId} AND RoleName=#{RoleName}")
    public List<Roles> getNameCount(@Param("AppId") String AppId,@Param("RoleName") String RoleName);

    //查询同一个APPID下RoleName是否重复
    @Select("select * from roles where AppId=#{AppId} AND RoleName=#{RoleName} and Id<> #{Id}")
    public List<Roles> getNameCountNoId(@Param("AppId") String AppId,@Param("RoleName") String RoleName,@Param("Id") String Id);


    @Select("<script>" +
            "select * from roles where 1=1 " +
            "" +
            " <when test='keyword!=null'>" +
            " AND (RoleCode like concat('%',#{keyword},'%') or RoleName like concat('%',#{keyword},'%') )" +
            " </when>" +
            "" +
            " <when test='AppId!=null'>" +
            " AND AppId=#{AppId}" +
            " </when>" +
            "</script>")
    public List<Roles> searchRolesList(GetRolesInput input);
}
